from tailfollow import TailFollow
from time import sleep

class TailStream(TailFollow):
    """Wrapper for ``Tailfollow`` that provides a slightly cleaner
    interface when the only task required is to endlessly process a
    stream.
    """

    def __init__(self, filename, sleep=1, offset=0, whence=0):
        """Constructor that specifies the file to be tailed. Optional
        keyword argument specifies the sleep interval, the offset to
        start reading from and the positioning from where to make that
        offset from.
        """
        self.done = False
        self.sleep = sleep
        TailFollow.__init__(self, filename, offset=0, whence=0)


    def next(self):
        while True:
            try:
                return TailFollow.next(self)
            except StopIteration:
                if self.done:
                    raise
                sleep(self.sleep)
